package com.hrt.web.member.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hrt.bean.HRTMember;
import com.hrt.util.MD5Tool;
import com.hrt.util.MailUtil;
import com.hrt.web.member.dao.HRTMemberDao;
import com.hrt.web.member.service.HRTMemberService;
@Service
@Transactional
public class HRTMemberServicesImpl implements HRTMemberService{
	private HRTMemberDao hRTMemberDao;

	@Resource
	public void setHRTMemberDao(HRTMemberDao hRTMemberDao) {
		this.hRTMemberDao = hRTMemberDao;
	}

	@Override
	public void registerMember(HRTMember hu) {
		//md5加密
		String pwd = hu.getPassword();
		String md5_Pwd = MD5Tool.MD5(pwd);
		hu.setPassword(md5_Pwd);
		hRTMemberDao.addHRTMember(hu);
	}

	@Override
	public HRTMember loginMember(String uname, String pwd) {
		pwd = MD5Tool.MD5(pwd);
		return hRTMemberDao.checkHRTMemberOfUnamePwd(uname, pwd);
	}

	@Override
	public Boolean findMember(String uname) {
		
		Boolean b = true;
		HRTMember hu = hRTMemberDao.checkHRTMemberOfUnamePwd(uname, null);
		if(hu!=null)
			b=false;
		return b;
	}

	@Override
	public void sendMail(String toMail,String jym) {
		MailUtil sendmail = new MailUtil();
		//设置邮箱服务器,当前位163邮箱服务器
		sendmail.setHost("smtp.163.com");
		//发件人姓名，与邮箱可一致
		sendmail.setUserName("lisiyuan_job@163.com");
		//发件人邮箱密码
		sendmail.setPassWord("a1994520");
		//收件人邮箱地址
		sendmail.setTo(toMail);
		//发件人邮箱地址
		sendmail.setFrom("lisiyuan_job@163.com");
		//邮件主题
		sendmail.setSubject("何人堂网站注册验证");
		//邮件内容
		sendmail.setContent("请点击此链接：http://localhost:8080/HRTWeb3/HRTWEB/mailCheckInfo.do?jym="+jym+"&toMail="+toMail);
		sendmail.sendMail();
	}

	@Override
	public void updateMemberActivate(HRTMember hu) {
		hRTMemberDao.updateHRTMemberMailCheck(hu);
	}

	@Override
	public void updateHRTMember(HRTMember hu) {
		hRTMemberDao.updateEntity(hu);
		
	}

	@Override
	public HRTMember getMemberByid(Long id) {
		return hRTMemberDao.getById(id);
	}

	@Override
	public void sendMailPass(String toMail, String jym) {
		MailUtil sendmail = new MailUtil();
		//设置邮箱服务器,当前位163邮箱服务器
		sendmail.setHost("smtp.163.com");
		//发件人姓名，与邮箱可一致
		sendmail.setUserName("lisiyuan_job@163.com");
		//发件人邮箱密码
		sendmail.setPassWord("a1994520");
		//收件人邮箱地址
		sendmail.setTo(toMail);
		//发件人邮箱地址
		sendmail.setFrom("lisiyuan_job@163.com");
		//邮件主题
		sendmail.setSubject("何人堂网站注册验证");
		//邮件内容
		sendmail.setContent("请点击此链接：http://localhost:8080/HRTWeb3/HRTWEB/mailCheckPass.do?jym="+jym+"&toMail="+toMail);
		sendmail.setContent("您的密码是："+jym);
		sendmail.sendMail();
		
	}
	/* 
	 * 根据会员名称查找会员实体
	 */
	@Override
	public HRTMember getMemberByName(String name) {
		return hRTMemberDao.queryByName(name);
	}

	@Override
	public HRTMember findMobile(String mobile) {
		return hRTMemberDao.findMobile(mobile);
	}

	@Override
	public void addHRTMember(HRTMember hu) {
		hRTMemberDao.addHRTMember(hu);
		
	}

	@Override
	public void saveMember(HRTMember member) {
		hRTMemberDao.saveEntity(member);
		
	}

	@Override
	public HRTMember getByMail(String mail) {
		// TODO Auto-generated method stub
		return hRTMemberDao.getByMail(mail);
	}

}
